<?php
class Comment_Model_Comment extends Zend_Db_Table{
	protected $_name = 'comment';
	protected $_primary = 'comment_id';
	/* Link tham khao : http://framework.zend.com/manual/en/zend.db.table.html */
	
	// ham lay thong tin comment len
	public function getCommentbyID($thing_id,$page,$offset)
	{// co dung
		//lay thong tin comment theo thing_id
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/comment/route/getCommentbyID/thing_id/".$thing_id."/page/".$page."/offset/".$offset);
		if(trim($return->getBody())!="")
		{
			$return = json_decode(json_encode((array) simplexml_load_string($return->getBody())),1);
			for ($i=0;$i <count($return);$i++)
				$data[$i] = $return['row_'.$i];
		}
		else $data = null;
		
		return $data;
	}
	// ham them mot comment
	public function insertComment($data)
	{ // co dung
		$data['route'] = "insertComment";
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restPost("/comment", $data);

		return $return->getBody();
	
	}
	
	// ham dem xem co bao nhieu comment
	public function countCommentbyID($ID)
    { // co dung   
   		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/comment/route/countCommentbyID/ID/".$ID)->getBody();
		if($return=="") $data = 0;
		else $data = $return;
		return $data;

    }
	
	//ham xoa comment
	public function deleteCommentByID($id)
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restDelete("/comment/route/deleteCommentByID/id/".$id);
		return $return->getBody();
	}
	
}
?>
